<?php

class Web_Admin_Pedidos_DetallePedido extends Web_Admin_MainPage
{

    public function mainContent()
    {
//        $this->add_js_link(BASE_WEB_ROOT . '/js/jquery.js');
        return $this->detalle();
    }

    private function detalle()
    {
        $car_id = Ey::getPrm(3);
        
        $_SESSION['car_id'] = $car_id;
        
        $obj = new Web_Db_CarritoDetalle();
        $db = $obj->getAdapter();
        $carrito = $db->fetchAll($obj->select()
                                ->where('det_car_id=?', $car_id));

        foreach ($carrito as $value) {
            $link = '<a href="' . WEB_ROOT . '/admin/productos/detalle-producto/' . $value->det_pro_id . '" class="deta" >' . $value->det_pro_nombre . '</a>';
            $value->det_pro_nombre = $link;
            $total+=$value->det_pro_precio;
        }

        $obj2 = new Web_Db_CarritoDireccion();
        $db2 = $obj2->getAdapter();
        $direccion = $db2->fetchAll($obj2->select()
                                ->where('dir_car_id=?', $car_id));

        $obj3 = new Web_Db_Carrito();
        $db3 = $obj3->getAdapter();
        $caritoDato = $db3->fetchRow($obj3->select()
                                ->where('car_id=?', $car_id));

        $obj4 = new Web_Db_Clientes();
        $db4 = $obj4->getAdapter();
        $cliente = $db4->fetchRow($obj4->select()
                                ->where('cli_id=?', $caritoDato->car_usu_id));

//        print_r($carrito);
        
        $smarty = new Smarty_Engine();
        $smarty->assign('total', $total);
        $smarty->assign('carrito', $carrito);
        $smarty->assign('direccion', $direccion);
        $smarty->assign('caritoDato', $caritoDato);
        $smarty->assign('cliente', $cliente);

        return $smarty->fetch(ADMIN_PEDIDOS_DIR . DS . 'tpl' . DS . 'detalle-pedido.tpl');
    }

}